home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Creative Computers
/
Creative Computers CD-ROM, Volume 1 (Legendary Design Technologies, Inc.)(1994).iso
/
shareware
/
telecom
/
term_4.1
/
extras
/
hydracom
/
source
/
amiga.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-11-17
|
42KB
|
1,865 lines
/*
** Amiga support module for HYDRA protocol sample implementation.
**
** Written by Olaf Barthel
** Brabeckstrasse 35
** D-30559 Hannover
**
** eMail: olsen@sourcery.han.de
**
** Freely distributable.
*/
/* System includes. */
#include <intuition/intuitionbase.h>
#include <libraries/gadtools.h>
#include <graphics/gfxbase.h>
#include <utility/date.h>
#include <devices/conunit.h>
#include <devices/serial.h>
#include <devices/timer.h>
#include <hardware/cia.h>
#include <dos/dosextens.h>
#include <dos/filehandler.h>
#include <dos/dosasl.h>
#include <exec/memory.h>
/* Correct a nasty bug in the prototypes. */
#define CheckIO foo21234
#include <clib/intuition_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/graphics_protos.h>
#include <clib/utility_protos.h>
#include <clib/timer_protos.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/macros.h>
/* Get the CheckIO prototype right. */
#undef CheckIO
struct IORequest *CheckIO(struct IORequest *);
#include "Rendezvous.h"
#include "hydracom.h"
/* Serial buffer size. */
#define BUFFER_SIZE 8192
/* A handy macro. */
#define ClrSignal(s) SetSignal(0,s)
/* Signal masks. */
#define SIG_SERREAD (1UL << ReadPort -> mp_SigBit)
#define SIG_SERWRITE (1UL << WritePort -> mp_SigBit)
#define SIG_CONREAD (1UL << ConsoleReadPort -> mp_SigBit)
#define SIG_TIMER (1UL << TimePort -> mp_SigBit)
#define SIG_WINDOW (1UL << LocalWindow -> UserPort -> mp_SigBit)
/* A serial buffer structure. */
struct SerialBuffer
{
struct IOExtSer *SerialRequest;
UBYTE *SerialBuffer,
*SerialIndex,
*SerialTop;
LONG SerialSize,
SerialFilled;
BOOL IsClone,
IsBusy;
};
STATIC struct RendezvousData *RendezvousData;
STATIC struct RendezvousSemaphore *RendezvousSemaphore;
/* Library bases. */
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
struct Library *GadToolsBase,
*UtilityBase,
*TimerBase;
/* Timer data. */
struct MsgPort *TimePort;
struct timerequest *TimeRequest;
/* Serial data. */
struct MsgPort *ReadPort,
*WritePort;
struct SerialBuffer *ThisBuffer,
*NextBuffer,
*ReadBuffer;
/* Console data. */
struct Window *FileWindow,
*RemoteWindow,
*LocalWindow,
*LogWindow;
struct MsgPort *ConsoleWritePort,
*ConsoleReadPort;
struct IOStdReq *ConsoleReadRequest;
UBYTE ConsoleChar;
BOOL ConsoleReady = FALSE,
WindowReady = FALSE;
struct IOStdReq *FileRequest,
*RemoteRequest,
*LocalRequest,
*LogRequest;
/* DOS Data. */
struct Process *ThisProcess;
APTR OldPtr;
struct AnchorPath *Anchor;
BOOL AnchorUsed = FALSE;
/* Screen data. */
struct Screen *PublicScreen,
*Screen;
/* Menu data. */
APTR VisualInfo;
struct Menu *Menu;
struct NewMenu MenuTemplate[] =
{
{ NM_TITLE, "Project", 0 , 0, 0, (APTR)0},
{ NM_ITEM, "Toggle chat", "C", 0, 0, (APTR)Alt_C},
{ NM_ITEM, NM_BARLABEL, 0 , 0, 0, (APTR)0},
{ NM_ITEM, "Hang up", "H", 0, 0, (APTR)Alt_H},
{ NM_ITEM, "Toggle duplex", "E", 0, 0, (APTR)Alt_E},
{ NM_ITEM, "Toggle 7 bits/8 bits", "B", 0, 0, (APTR)Alt_B},
{ NM_ITEM, NM_BARLABEL, 0 , 0, 0, (APTR)0},
{ NM_ITEM, "Start upload", "U", 0, 0, (APTR)PgUp},
{ NM_ITEM, "Start download", "D", 0, 0, (APTR)PgDn},
{ NM_ITEM, NM_BARLABEL, 0 , 0, 0, (APTR)0},
{ NM_ITEM, "Exit HydraCom", "Q", 0, 0, (APTR)Alt_X},
{ NM_END, 0, 0 , 0, 0, (APTR)0}
};
/* OpenConsole():
*
* Open a console window.
*/
STATIC BOOL __inline
OpenConsole(struct Screen *Screen,LONG Top,LONG Height,STRPTR Title,BOOL Resize,struct Window **WindowPtr,struct IOStdReq **ConsolePtr)
{
struct Window *Window;
if(Window = OpenWindowTags(NULL,
WA_Left, 0,
WA_Top, Top,
WA_Width, Screen -> Width,
WA_Height, Height,
WA_Title, Title,
WA_SimpleRefresh, TRUE,
WA_DepthGadget, TRUE,
WA_DragBar, TRUE,
WA_SizeGadget, Resize,
WA_SizeBRight, TRUE,
WA_CustomScreen, Screen,
WA_RMBTrap, TRUE,
WA_NewLookMenus, TRUE,
TAG_DONE))
{
struct IOStdReq *ConsoleRequest;
if(Window -> RPort -> Font -> tf_Flags & FPF_PROPORTIONAL)
SetFont(Window -> RPort,GfxBase -> DefaultFont);
if(ConsoleRequest = (struct IOStdReq *)CreateIORequest(ConsoleWritePort,sizeof(struct IOStdReq)))
{
ConsoleRequest -> io_Data = Window;
if(!OpenDevice("console.device",CONU_CHARMAP,ConsoleRequest,CONFLAG_DEFAULT))
{
WindowLimits(Window,Window -> BorderLeft + 10 * Window -> RPort -> Font -> tf_XSize * 10 + Window -> BorderRight,Window -> BorderTop + 2 * Window -> RPort -> Font -> tf_YSize + Window -> BorderBottom,Screen -> Width,Screen -> Height);
/* Turn off the cursor. */
ConPrintf(ConsoleRequest,"\033[0 p");
*WindowPtr = Window;
*ConsolePtr = ConsoleRequest;
return(TRUE);
}
DeleteIORequest(ConsoleRequest);
}
CloseWindow(Window);
}
return(FALSE);
}
/* CloseConsole():
*
* Close a console window.
*/
STATIC VOID __inline
CloseConsole(struct Window **WindowPtr,struct IOStdReq **ConsolePtr)
{
if(*ConsolePtr)
{
CloseDevice(*ConsolePtr);
DeleteIORequest(*ConsolePtr);
*ConsolePtr = NULL;
}
if(*WindowPtr)
{
CloseWindow(*WindowPtr);
*WindowPtr = NULL;
}
}
/* CloneSerialBuffer():
*
* Clone a SerialBuffer structure.
*/
STATIC struct SerialBuffer * __regargs
CloneSerialBuffer(struct SerialBuffer *Source,struct MsgPort *MsgPort)
{
struct SerialBuffer *Buffer;
if(Buffer = (struct SerialBuffer *)AllocVec(sizeof(struct SerialBuffer) + Source -> SerialSize,MEMF_ANY | MEMF_PUBLIC))
{
Buffer -> SerialBuffer = Buffer -> SerialIndex = (UBYTE *)(Buffer + 1);
Buffer -> SerialFilled = 0;
Buffer -> SerialTop = Buffer -> SerialBuffer + Source -> SerialSize;
Buffer -> SerialSize = Source -> SerialSize;
Buffer -> IsClone = TRUE;
Buffer -> IsBusy = FALSE;
if(Buffer -> SerialRequest = (struct IOExtSer *)AllocVec(sizeof(struct IOExtSer),MEMF_ANY | MEMF_PUBLIC))
{
CopyMem(Source -> SerialRequest,Buffer -> SerialRequest,sizeof(struct IOExtSer));
Buffer -> SerialRequest -> IOSer . io_Message . mn_ReplyPort = MsgPort;
return(Buffer);
}
else
cprint("Could not create serial request\n");
FreeVec(Buffer);
}
else
cprint("Could not create serial buffer\n");
return(NULL);
}
/* DeleteSerialBuffer():
*
* Delete a SerialBuffer structure.
*/
STATIC VOID __regargs
DeleteSerialBuffer(struct SerialBuffer *Buffer)
{
if(Buffer)
{
if(Buffer -> IsBusy)
{
if(!CheckIO(Buffer -> SerialRequest))
AbortIO(Buffer -> SerialRequest);
WaitIO(Buffer -> SerialRequest);
}
if(Buffer -> IsClone)
FreeVec(Buffer -> SerialRequest);
else
{
CloseDevice(Buffer -> SerialRequest);
DeleteIORequest(Buffer -> SerialRequest);
}
FreeVec(Buffer);
}
}
/* CreateSerialBuffer():
*
* Create a serial buffer structure.
*/
STATIC struct SerialBuffer * __regargs
CreateSerialBuffer(STRPTR Device,LONG Unit,LONG Size,struct MsgPort *MsgPort)
{
struct SerialBuffer *Buffer;
if(Buffer = (struct SerialBuffer *)AllocVec(sizeof(struct SerialBuffer) + Size,MEMF_ANY | MEMF_PUBLIC))
{
Buffer -> SerialBuffer = Buffer -> SerialIndex = (UBYTE *)(Buffer + 1);
Buffer -> SerialFilled = 0;
Buffer -> SerialTop = Buffer -> SerialBuffer + Size;
Buffer -> SerialSize = Size;
Buffer -> IsClone = FALSE;
Buffer -> IsBusy = FALSE;
if(Buffer -> SerialRequest = (struct IOExtSer *)CreateIORequest(MsgPort,sizeof(struct IOExtSer)))
{
if(!OpenDevice(Device,Unit,Buffer -> SerialRequest,NULL))
return(Buffer);
else
{
cprint("Could not open \"%s\", unit %d\n",Device,Unit);
DeleteIORequest(Buffer -> SerialRequest);
}
}
else
cprint("Could not create serial request\n");
FreeVec(Buffer);
}
else
cprint("Could not create serial buffer\n");
return(NULL);
}
/* OpenAll():
*
* Allocate all the resources required.
*/
STATIC BOOL
OpenAll(STRPTR Device,LONG Unit)
{
LONG Top,Lines,BorderSize,FontSize,ExtraLines,RemainingLines,TotalHeight;
UWORD Pens = (UWORD)~0;
if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",37)))
{
cprint("Could not open intuition.library v37\n");
return(FALSE);
}
if(!(Gfx